# -*- coding: utf-8 -*-
# 创建时间：2021/8/7 17:53
from bs4 import BeautifulSoup
import requests
import time, math, random, json
import pymysql
import re
from xlwt import Workbook
__author__ = 'LuckyHhy'


def get_data():
    url="http://api.sports.163.com/base/cs/union/schedule/groupByRounds?cid=282"
    response=requests.get(url)
    result = response.json()
    data_arr=result['data']['scheduleGroup']
    data = []
    for item in data_arr:
        for it in item['schedules']:
            #print(it)
            zd = [it['home'], it['homeLogo']]  # 主队
            data.append(zd)
            kd = [it['away'], it['awayLogo']]  # 客队
            data.append(kd)

    return data


# 保存到excel 文件
def save_xls(pathh):
    w = Workbook()
    ws = w.add_sheet('datas')  # 创建一个工作表

    results = get_data()
    i = 0
    for row in results:
        g = 0
        # print(f"正在执行第{i}行数据")
        for jj in row:
            ws.write(i, g, jj)  # 行 ，列  数据
            g = g + 1
        i = i + 1

    print("已经跳出来了")
    w.save(pathh)

def main():
    pathh = '中超赛程数据.xls'  # 存放路径
    save_xls(pathh)
    print("下载结束")
    pass


if __name__ == '__main__':
    main()
